package io.renren.modules.shop.service.impl;

import io.renren.modules.shop.entity.ProductDetailEntity;
import io.renren.modules.shop.entity.ProductDetailRackEntity;
import io.renren.modules.shop.entity.ProductPictureEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.shop.dao.ProductDao;
import io.renren.modules.shop.entity.ProductEntity;
import io.renren.modules.shop.service.ProductService;

import javax.annotation.Resource;


@Service("productService")
public class ProductServiceImpl extends ServiceImpl<ProductDao, ProductEntity> implements ProductService {

    @Resource ProductDao productDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProductEntity> page = this.page(
                new Query<ProductEntity>().getPage(params),
                new QueryWrapper<ProductEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params, Integer category) {
        IPage<ProductEntity> page = this.page(
                new Query<ProductEntity>().getPage(params),
                new QueryWrapper<ProductEntity>()
                        .lambda().eq(ProductEntity::getCategoryId,category)
        );

        return new PageUtils(page);
    }

    @Override
    public List<ProductPictureEntity> getProductPicture(Long id) {
        return productDao.getProductPicture(id);
    }

    @Override
    public ProductDetailEntity getDetailById(Long id) {
        return productDao.getProductDetailById(id);
    }

    @Override
    public List<ProductDetailEntity> getProductBySearch(String search) {
        return productDao.getProductBySearch(search);
    }

    @Override
    public List<ProductDetailEntity> getProductBySearch(String search, Integer rack) {
        return productDao.getProductBySearchOne(search,rack);
    }

    @Override
    public List<ProductDetailEntity> getProductByCategory(Integer categoryId) {
        return productDao.getProductByCategory(categoryId);
    }

    @Override
    public List<ProductDetailEntity> getProductByCategory(Integer categoryId, Integer rack) {
        return productDao.getProductByCategoryOne(categoryId,rack);
    }

    @Override
    public List<ProductDetailRackEntity> getMerchant(Long id) {
        return productDao.getMerchant(id);
    }

    @Override
    public List<ProductDetailRackEntity> getMerchant(Long id, Integer rack) {
        return productDao.getMerchantRack(id,rack);
    }


}
